*==============================================================================*
*===*                 Estimations for Ukraine Framing effects                  *===*
*==============================================================================*

* Date: October 2025
* Author: [ommitted for reviewing]


****===========================================================================*
**#*===* 0.  Preamble

global main = "C:"

global inputs = "$main/Inputs"
global tables = "$main/Tables"
global figures = "$main/Figures"

use "C:\UMD CIP May 2022 Weighted Data_Framing.dta"

cd "$main/Tables"

* Some extra cleaning

****
****
**** Experiment Zelensky
****
****
rename PDEMSPAN Latinx
rename INSURVEYINCOME Income
rename INSURVEYEDU Education
rename INSURVEYAGE Age
gen Woman= PDEMSEX-1
label define Woman 0 "Man" 1 "Woman", replace
label values Woman Woman
gen infoInternet=0
replace infoInternet=1 if Q51==10
label define infoInternet 0 "Other Sources" 1 "Internet", replace
label values infoInternet infoInternet
label variable infoInternet "News Primarily from Internet"


rename Hid_Image Treatment
label variable Treatment "Four Treatment Images"
label define Treatment 1 "FoxNews, True" 2 "FoxNews, False" 3 "NYT, True" 4 "NYT, False", replace
label values Treatment Treatment
gen True=0
replace True=1 if (Treatment==1 | Treatment==3)
label variable True "True, Confirmation"
label define True 0 "False" 1 "True", replace
label values True True

gen NYT=0
replace NYT=1 if (Treatment==3 | Treatment==4)
label define NYT 0 "FoxNews" 1 "NYT", replace
label values NYT NYT
label variable NYT "News Organization Post"

gen ideology= Q10GROUP1_A
replace ideology= Q10GROUP2_A if ideology==.
label variable ideology "Ideology"
gen ideoFox= Q10GROUP1_B
replace ideoFox= Q10GROUP2_B if ideoFox==.
label variable ideoFox "Ideology FoxNews"
gen ideoNYT= Q10GROUP1_C
replace ideoNYT= Q10GROUP2_C if ideoNYT==.
label variable ideoNYT "Ideology New York Times"
gen TreatedPost=0
replace TreatedPost=1 if Q10GROUP2_A!=.
label define TreatedPost 0 "Pre-Treatment Group" 1 "Post-Treatment Group", replace
label values TreatedPost TreatedPost
label variable TreatedPost "Ideology after Facebook Post"
gen lnideology= ln(ideology/abs(8-ideology))
gen lnideoFox= ln(ideoFox/abs(8-ideoFox))
gen lnideoNYT= ln(ideoNYT/abs(8-ideoNYT))

rename Q8_1 Like
label define Like 0 "No Like" 1 "Like", replace
label values Like Like
label variable Like "Like"
rename Q8_2 Comment
label define Comment 0 "No Comment" 1 "Comment", replace
label values Comment Comment
label variable Comment "Comment"
rename Q8_3 Share
label define Share 0 "No Share" 1 "Share", replace
label values Share Share
label variable Share "Share"
rename Q8_4 Ignore
label define Ignore 0 "No Ignore" 1 "Ignore", replace
label values Ignore Ignore
label variable Ignore "Ignore"
gen Engage = abs(1-Ignore)
label define Engage 0 "No Engage" 1 "Engage", replace
label values Engage Engage
label variable Engage "Engage"

gen voteBiden=0
replace voteBiden=1 if Q50A==2
label define voteBiden 0 "Other" 1 "Biden", replace
label values voteBiden voteBiden
label variable voteBiden "Biden Voter"

gen voteTrump=0
replace voteTrump=1 if Q50A==1
label define voteTrump 0 "Other" 1 "Trump", replace
label values voteTrump voteTrump
label variable voteTrump "Trump Voter"

gen vote="Donald Trump" if voteTrump==1
replace vote="Joe Biden" if voteBiden==1
encode vote, gen(vote_encode)

gen race="White" if PDEMRACEWHITE==1
replace race="Black/African American" if PDEMRACEBLACK==1
replace race="Other" if race==""
encode race, gen(race_encode)

gen lntimetoreadV1=ln(PAGETIMEINFO)
gen lntimetoreactV1=ln(PAGETIMEQ8)
gen lntimetosentV1=ln(PAGETIMEQ9) 

xi, noomit: sum i.Q9
rename _IQ9_1 Angry
label variable Angry ""
rename _IQ9_2 Happy
label variable Happy ""
rename _IQ9_3 Disgusted
label variable Disgusted ""
rename _IQ9_4 Fearful
label variable Fearful ""
rename _IQ9_5 Sad
label variable Sad ""
rename _IQ9_6 Stressed
label variable Stressed ""
rename _IQ9_7 Indifferent
label variable Indifferent ""


******************
**Figure 2
******************
twoway (histogram lntimetoreadV1 if True==1, start(0) width(.1) color(red%30)) (histogram lntimetoreadV1 if True==0, start(0) width(.1) color(blue%30)), legend(order(1 "Confirmation" 2 "Refutation" )) sch(538) title("Time to Read, By Confirmation (True Label) or Refutation (False Label)") xtitle("Time-to-Read(LN)")

******************
**Figure 3
******************

graph twoway (lfitci  Engage lntimetoreadV1 if True==1 & lntimetoreadV1 >2 & lntimetoreadV1 <4, msize(small) lcolor("gs10")  color("green%70")) (lfitci  Engage lntimetoreadV1 if True==0 & lntimetoreadV1 >2 & lntimetoreadV1 <4, msize(small) lcolor("gs7") color("red%70")), aspect(0) sch(538) ytitle("Proportion of Engage (Like, Share, Comment)", size(small)) xtitle("Time-to-Read (LN)")  title("Time-to-Read and Engagement with the Facebook Post", size(small)) leg(order(1 3) label(1 "Confirmation") label(3 "Refutation") cols(1) symysize(3) forcesize ring(0) bplacement(nwest))

******************
**Figure 3, share
******************

graph twoway (lfitci  Share lntimetoreadV1 if True==1 & lntimetoreadV1 >2 & lntimetoreadV1 <4, msize(small) lcolor("gs10")  color("green%70")) (lfitci  Share lntimetoreadV1 if True==0 & lntimetoreadV1 >2 & lntimetoreadV1 <4, msize(small) lcolor("gs7") color("red%70")), aspect(0) sch(538) ytitle("Proportion of Sharing", size(small)) xtitle("Time-to-Read (LN)")  title("Time-to-Read and Sharing with the Facebook Post", size(small)) leg(order(1 3) label(1 "True") label(3 "False") cols(1) symysize(3) forcesize ring(0) bplacement(nwest))


*--- Figure A: Sharing (top) -----------------------------------------------
graph twoway (lfitci Share lntimetoreadV1 if True==1 & inrange(lntimetoreadV1,2,4), msize(small) lcolor("gs10") color("green%30")) (lfitci Share lntimetoreadV1 if True==0 & inrange(lntimetoreadV1,2,4), msize(small) lcolor("gs7")  color("red%30")), aspect(0) ytitle("Proportion of Sharing", size(small)) xtitle("Time-to-Read (LN)") title("Time-to-Read and Sharing with the Facebook Post", size(small)) legend(order(1 3) label(1 "Confirmation") label(3 "Refutation") cols(1) symysize(3) forcesize ring(0) bplacement(nwest)) name(g_share, replace) nodraw

*--- Figure B: Engagement (bottom) -----------------------------------------
graph twoway (lfitci Engage lntimetoreadV1 if True==1 & inrange(lntimetoreadV1,2,4), msize(small) lcolor("gs10") color("green%30")) (lfitci Engage lntimetoreadV1 if True==0 & inrange(lntimetoreadV1,2,4), msize(small) lcolor("gs7")  color("red%30")), aspect(0) ytitle("Proportion of Engage (Like, Share, Comment)", size(small))xtitle("Time-to-Read (LN)") title("Time-to-Read and Engagement with the Facebook Post", size(small)) legend(order(1 3) label(1 "Confirmation") label(3 "Refutation") cols(1) symysize(3) forcesize ring(0) bplacement(nwest)) name(g_engage, replace) nodraw

*--- Combine: Sharing on top, Engagement below -----------------------------
graph combine g_share g_engage, rows(1) ysize(3) xsize(7) imargin(2 4 2 4)
graph export "E:\Dropbox\Apps\Overleaf\PAP_Ukraine Experiment\Figures\Engage and Time to Read.png", as(png) name("Graph") replace

******************
**Figures 4 and 5
******************

* prereqs
cap which coefplot
if _rc ssc install coefplot
est drop _all

*---- SHARE ------------------------------------------------------
logit Share i.partyid##i.NYT if True==1
margins, by(partyid) post
est store ShareTrue

logit Share i.partyid##i.NYT if True==0
margins, by(partyid) post
est store ShareFalse

coefplot  ///
    (ShareTrue,  mc(green%90) m(S) ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(green%90))) ///
    (ShareFalse, mc(red%90)   m(S) ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(red%90)))  ///
    , sch(538) levels(95) vertical citop format(%9.2f) fcolor(*.5) ///
      ytitle("Predicted Pr(Share)", size(small)) ///
      xlab(, labsize(*1.1)) yti(, size(*.9)) ylab(, labsize(*.8)) ///
      addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black) mlabsize(vsmall)) ///
      legend(order(1 3) label(1 "Confirmation") label(3 "Refutation") cols(1) symysize(3) forcesize ring(0) bplacement(swest)) ///
      title("Zelensky Experiment — Sharing by Condition & Party", size(small)) ///
      name(g_share, replace) nodraw

*---- ENGAGE -----------------------------------------------------
logit Engage i.partyid##i.NYT if True==1
margins, by(partyid) post
est store EngageTrue

logit Engage i.partyid##i.NYT if True==0
margins, by(partyid) post
est store EngageFalse

coefplot  ///
    (EngageTrue, mc(green%90)  m(S) ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(green%90))) ///
    (EngageFalse, mc(red%90)  m(S) ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(red%90)))  ///
    , sch(538) levels(95) vertical citop format(%9.2f) fcolor(*.5) ///
      ytitle("Predicted Pr(Engage: Like/Share/Comment)", size(small)) ///
      xlab(, labsize(*1.1)) yti(, size(*.9)) ylab(, labsize(*.8)) ///
      addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black) mlabsize(vsmall)) ///
      legend(order(1 3) label(1 "Confirmation") label(3 "Refutation") cols(1) symysize(3) forcesize ring(0) bplacement(swest)) ///
      title("Zelensky Experiment — Engagement by Condition & Party", size(small)) ///
      name(g_engage, replace) nodraw

*---- COMBINE (Sharing on top, Engagement below) -----------------
graph combine g_share g_engage, rows(2) imargin(2 4 2 4) ysize(6) xsize(7)
graph export "E:\Dropbox\Apps\Overleaf\PAP_Ukraine Experiment\Figures\Share_Engage_byParty.png", ///
    as(png) name("Graph") replace


*==================== SHARE: by condition & media (within party) ====================
logit Share i.partyid##i.NYT if True==1
margins, by(NYT partyid) post
est store ShareMediaTrue

logit Share i.partyid##i.NYT if True==0
margins, by(NYT partyid) post
est store ShareMediaFalse

*================== SHARE: by condition & media (within party) ====================

* Define labels (only needs to be done once, but harmless if repeated)
label define partyidlbl 1 "Republican" 2 "Democrat" 3 "Independent", replace
label values partyid partyidlbl
label define NYTlbl 0 "Fox News" 1 "NYT", replace
label values NYT NYTlbl

* Models
logit Share i.partyid##i.NYT if True==1
margins, by(NYT partyid) post
est store ShareMediaTrue

logit Share i.partyid##i.NYT if True==0
margins, by(NYT partyid) post
est store ShareMediaFalse

* Plot
coefplot (ShareMediaTrue,  label("Confirmation") mc(green%90) m(S) ///
              ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(green%90))) ///
         (ShareMediaFalse, label("Refutation") mc(red%50) m(S) ///
              ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(red%90))) ///
    , sch(538) levels(95) vertical fcolor(*.5) citop format(%9.2f) ///
      ytitle("Sharing") xlab(1 "Republican" 2 "Democrat" 3 "Independent" ///
                             4 "Republican" 5 "Democrat" 6 "Independent", labsize(*1.1)) ///
      addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black) mlabsize(vsmall)) ///
      graphregion(color(white)) ///
	  xline(3.5, lcolor(gs10) lpattern(solid)) ///
      text(0 2 "Fox News" 0 5 "NYT", size(medium) place(n)) ///
      legend(cols(1) symysize(3) forcesize ring(0) bplacement(nwest) size(vsmall)) ///
      title("Zelensky Experiment, Sharing by Confirmation Condition, Media, and Party") ///
      name(g_share_media, replace)

*================== ENGAGE: by condition & media (within party) ====================
* Define labels

* Models
logit Engage i.partyid##i.NYT if True==1
margins, by(NYT partyid) post
est store EngageMediaTrue

logit Engage i.partyid##i.NYT if True==0
margins, by(NYT partyid) post
est store EngageMediaFalse

* Plot
coefplot (EngageMediaTrue, label("Confirmation") mc(green%90) m(S) ///
              ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(green%90))) ///
         (EngageMediaFalse, label("Refutation") mc(red%50) m(S) ///
              ciopts(recast(rbarm) lw(.4) lp(solid) bcolor(red%90))) ///
    , sch(538) levels(95) vertical fcolor(*.5) citop format(%9.2f) ///
      ytitle("Engage") xlab(1 "Republican" 2 "Democrat" 3 "Independent" ///
                             4 "Republican" 5 "Democrat" 6 "Independent", labsize(*1.1)) ///
      addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black) mlabsize(vsmall)) ///
      graphregion(color(white)) ///
	  xline(3.5, lcolor(gs10) lpattern(solid)) ///
	  text(0 2 "Fox News" 0 5 "NYT", size(medium) place(n)) ///
      legend(cols(1) symysize(3) forcesize ring(0) bplacement(nwest) size(vsmall)) ///
      title("Zelensky Experiment, Engagement by Confirmation Condition, Media, and Party") ///
      name(g_engage_media, replace)

*=============================== COMBINE & EXPORT ================================
graph combine g_share_media g_engage_media, rows(2) imargin(2 4 2 4) ysize(6) xsize(7)
graph export "E:\Dropbox\Apps\Overleaf\PAP_Ukraine Experiment\Figures\Share_Engage_byCondition_Media_Party.png", ///
    as(png) name("Graph") replace


*****************
** Models
*****************

*****************
** Basic
*****************

local i = 1

foreach depv in `depvars' {
	ttest `depv', by(True) 
	mat balance_depv[`i', 1] = r(mu_1)
	mat balance_depv[`i', 2] = r(mu_2)
	mat balance_depv[`i', 3] = r(mu_2) - r(mu_1)
	mat balance_depv[`i', 4] = r(p)
	mat bal_depv_stars[`i', 3] = (r(p) <= .1) + (r(p) <= .05) + (r(p) <= .01)
	local i = `i' + 1
}

frmttable using "MainTable_Basic.tex", statmat(balance_depv) sdec(3) title("Effect of Confirmation and Refutation, Baseline") ctitle("Variable", "False", "True", "Diff", "P-value") rtitle("Engage"\"Like"\"Share"\"Comment"\"Ignore"\"Angry"\"Happy"\"Disgusted"\"Fearful"\"Sad"\"Stressed"\"Indifferent") annotate(bal_depv_stars) asymbol("*", "**", "***") tex replace


*****************
** With Controls
*****************

foreach depv in `depvars' {
	* Without controls
logit `depv' True i.(`contr_political') b(freq).(`contr_demog') i.(`contr_media')
outreg2 using "AllModels.tex", tex(frag) label dec(3) title("Framing effects on `depv' rates") ctitle(`depv') addstat(Diff, `diff', S.E., `se_d', p-val, `pval_d') append

}

***********************
*
*FULL MODELS (SIF)
*
***********************
foreach depv in `depvars' {
	* Without controls
	logit `depv' True, robust
	margins, dydx(True)
	mat def results = r(table)
	local diff = results[1,1]
	local se_d = results[2,1]
	local pval_d = results[4,1]
	margins, by(True) post
	outreg2 using "estim_`depv'.tex", tex(frag) label dec(3) title("Framing effects on `depv' rates") ctitle(`depv') addstat(Diff, `diff', S.E., `se_d', p-val, `pval_d') addtext("Controls", ".", "Political", "No", "Demographic", "No", "Media", "No") noaster replace
	
	
	* With political positioning controls
	logit `depv' True i.(`contr_political'), robust
	margins, dydx(True)
	mat def results = r(table)
	local diff = results[1,1]
	local se_d = results[2,1]
	local pval_d = results[4,1]
	margins, by(True) post
	outreg2 using "estim_`depv'.tex", tex(frag) label dec(3) ctitle(`depv') addstat(Diff, `diff', S.E., `se_d', p-val, `pval_d') addtext("Controls", ".", "Political", "Yes", "Demographic", "No", "Media", "No") noaster append
	
	* With political and demographic controls
	logit `depv' True i.(`contr_political') b(freq).(`contr_demog'), robust
	margins, dydx(True)
	mat def results = r(table)
	local diff = results[1,1]
	local se_d = results[2,1]
	local pval_d = results[4,1]
	margins, by(True) post
	outreg2 using "estim_`depv'.tex", tex(frag) label dec(3) ctitle(`depv') addstat(Diff, `diff', S.E., `se_d', p-val, `pval_d') addtext("Controls", ".", "Political", "Yes", "Demographic", "Yes", "Media", "No") noaster append

	* With political, demographic, and Media related controls
	logit `depv' True i.(`contr_political') b(freq).(`contr_demog') i.(`contr_media'), robust
	margins, dydx(True)
	mat def results = r(table)
	local diff = results[1,1]
	local se_d = results[2,1]
	local pval_d = results[4,1]
	margins, by(True) post
	outreg2 using "estim_`depv'.tex", tex(frag) label dec(3) ctitle(`depv') addstat(Diff, `diff', S.E., `se_d', p-val, `pval_d') addtext("Controls", ".", "Political", "Yes", "Demographic", "Yes", "Media", "Yes") noaster append

}


